package com.snatch.snatchmgr.core;

import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.snatch.common.utils.SpringUtil;
import com.snatch.common.vo.NodeTaskInput;
import com.snatch.snatchmgr.dto.SnatchItemDto;


/**
 * @ClassName: LiveCtrlManage
 * @Description: 盘中信息控制器
 * @author lilei
 * @date 2012-12-8 下午05:16:14
 * 
 */
@Component
public class SnatchCtrlManage {

	public ConcurrentHashMap<String, SnatchItemCore> snatchItemCoreMap = new ConcurrentHashMap<String, SnatchItemCore>();
	
	private Logger log = Logger.getLogger(SnatchCtrlManage.class);
	
	/**
	* @Title: initLiveMatch
	* @Description: 初始化盘中消费线程
	* @author lilei 
	* @param matchkey
	* @param matchName
	* @return
	* @return LiveBean        返回类型
	* @throws
	*/
	public void initSnatchItem(NodeTaskInput nodeTaskInput) {
		SnatchItemCore snatchItemCore = snatchItemCoreMap.get(nodeTaskInput.getTaskCode());
		if(null != snatchItemCore){
			return;
		}
		snatchItemCore =  (SnatchItemCore)SpringUtil.getBean("snatchItemCore");
		snatchItemCoreMap.put(nodeTaskInput.getTaskCode(), snatchItemCore);
		snatchItemCore.initSnatchItemCore(nodeTaskInput);
		snatchItemCore.startSnatchItemThread();
		// 创建CtrlBean，以及dataQueue对应的消费线程。
		log.info("采集线程" + nodeTaskInput.getTaskCode() + " 开始");
	}
	
	
	public SnatchItemCore findSnatchItemCore(String itemOnlyCode){
		return snatchItemCoreMap.get(itemOnlyCode);
	}
	

	/**
	 * @Title: destroyLiveMatch
	 * @Description: 销毁盘中控制BEAN
	 * @author lilei
	 * @param matchkey
	 * @return void 返回类型
	 * @throws
	 */
	public void destroyLiveMatch(String webkey) {
		SnatchItemCore snatchItemCore = snatchItemCoreMap.get(webkey);
		if(null != snatchItemCore){
			snatchItemCore.destroySnatchItemCore();
			snatchItemCore = null;
		}
	}
	
}
